home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Add-Ons / After Dark / Joe Judge / CyberWeb ƒ / (original BackInUse.c) next >
Encoding:
Text File  |  1994-07-17  |  5.5 KB  |  186 lines  |  [TEXT/KAHL]

  1. //•---------------------------------------------------------------------------•//
  2. //• "This Old Hack," modernized to run on Think C™ v.5.0.4, by Kenneth A. Long,
  3. //• on 24 July 1993, without the help of Norm Abrahm.  Free, so don't sell.
  4. //•---------------------------------------------------------------------------•//
  5. //• BackInUse.c        Original comments were left in and I added some.
  6. //•---------------------------------------------------------------------------•//
  7. //• Program INUSE.C for the Megamax C compiler
  8. //•  (C) 1986 William Woody, commercial rights reserved
  9.  
  10. //• If you think this program is cute, please send me computer mail and tell
  11. //• me so!  I personally think it's a cute hack, myself, but what do I know.
  12.  
  13. //• Though I don't believe this program has any commercial value,  (or ANY
  14. //• monitary value whatsoever), I have reserved commercial rights anyways.
  15. //• Silly me...  But if you want to give it to your friends, please leave
  16. //• my name on the darn thing; I need to feel appreciated.
  17. //•---------------------------------------------------------------------------•//
  18.  
  19. #include <stdio.h>
  20. #include <quickdraw.h>        //• What they don't tell you is that you need to
  21.                             //• include this for the SRAND macro to work...
  22.  
  23. #include <Picker.h>
  24. void RandomRGBColor(void);
  25.  
  26. //extern int Random ();
  27. // extern char *malloc ();
  28.  
  29. #define MAXX 480
  30. #define MAXY 300
  31. #define MAXM 400
  32.  
  33. WindowPtr theWindow;
  34.  
  35. WindowRecord wRecord;
  36. Rect        dragRect, linesRect, windowBounds = { 40, 2, 380, 508 };
  37.  
  38. struct foo {
  39.     double a,b;            //• This is a point which gets to fly around
  40.     struct foo *next;
  41. };
  42.  
  43. main ()
  44. {
  45.     int number,n,x,done = 0;
  46.     struct foo *top,*Ptr,*Ptr2;
  47.     
  48.     struct {
  49.         int top, left, bottom, right;
  50.     } linesRect;
  51.     
  52.     long ticks;        //• For the delay in the "splash" screen.
  53.     
  54.     short mx,my,nx,ny;
  55.     
  56.     MaxApplZone();
  57.     
  58.     InitGraf(&thePort);
  59.     InitFonts();
  60.     FlushEvents(everyEvent, 0);
  61.     InitWindows();
  62.     InitMenus();
  63.     TEInit();
  64.     InitDialogs(0L);
  65.     InitCursor();
  66.  
  67.     //• We can't drag because mouseDown quits us.  
  68.     //• But it's here if we want to rig it in later.
  69.     dragRect = screenBits.bounds;    
  70.  
  71. #if 0    
  72.     theWindow = NewWindow (&wRecord, &windowBounds, "\pIn Use", true, 0, 
  73.                      (WindowPtr)-1L, false, 0L);
  74. #else
  75.     theWindow = NewCWindow ( &wRecord, &windowBounds, "\pIn Use", true, 0,
  76.                     (WindowPtr)-1L, false, 0L);
  77. // example:                    
  78. // wind = NewCWindow( wStorage, &rBounds, title, visFlag, wDefProcID, 
  79. //                    behind, goAwayFlag, refCon );
  80. #endif
  81.     SetPort (theWindow);
  82.  
  83.  
  84.     //• We add a Rect to the window that we can draw in and erase.
  85.     SetRect (&linesRect,0,0,508,380);
  86.         
  87.     //• There's nothing to erase now, but if we had "about" info, it's ready.
  88.     EraseRect (&linesRect);
  89.         
  90.     MoveTo (10,25);
  91.     TextFont (systemFont);    
  92.     TextSize (12);
  93.     DrawString ("\pProgram InUse.C for the Megamax C compiler");
  94.     MoveTo (10,40);
  95.     DrawString ("\pCopyright©1985 by William Woody, commercial rights reserved.");
  96.     MoveTo (10,55);
  97.     DrawString ("\pTo halt the program, press the mouse Button.");
  98.     TextFont (courier);        //• Change font to Courier 12 bold.
  99.     TextSize (12);    
  100.     TextFace (bold);
  101.     MoveTo (10,70);
  102.     DrawString ("\pMade to run on Think C™ v.5.0.4 on 24 July 1993");
  103.     MoveTo (10,85);
  104.     DrawString ("\pBy Kenneth A. Long");    
  105.     GetDateTime (&randSeed);    //• Seed the random number generator
  106.     TextFont (0);
  107.     TextSize (12);    //• Set all the font stuff back so our SysParams are OK.
  108.     TextFace (0);
  109.     Delay (240L, &ticks);
  110.     EraseRect (&linesRect);        //• Get ready for action, after bragging.
  111.     
  112.     while  (!done) 
  113.     {
  114. //        EraseRect (&linesRect);        //• Added to not stack drawings up.
  115.         number =  (Random () & 3) + 2;    //• Number of points generated.
  116.         x = 0;
  117.             
  118. //        top = Ptr = (struct foo *) malloc(sizeof(struct foo));
  119.         top = Ptr = (struct foo *)NewPtr( sizeof(struct foo));
  120.         
  121.     //• While horizontal incrementing value is not the same 
  122.     //• as number of points...
  123.         while  (x++ != number)
  124.             Ptr =  (Ptr->next = (struct foo *) NewPtr (sizeof(struct foo)));
  125. //            Ptr =  (Ptr->next = (struct foo *) malloc (sizeof(struct foo)));
  126.  
  127.         Ptr =  (Ptr->next = top);
  128.         
  129.         mx = 0;
  130.         my = 0;
  131.         nx = 9999999.0;        //• Large numbers for finding minimum value.
  132.         ny = 9999999.0;
  133.         do 
  134.         {
  135.             Ptr->a =  (double) Random ();
  136.             if  (Ptr->a > mx) mx = Ptr->a;
  137.             if  (Ptr->a < nx) nx = Ptr->a;
  138.             
  139.             Ptr->b =  (double) Random ();
  140.             if  (Ptr->b > my) my = Ptr->b;
  141.             if  (Ptr->b < ny) ny = Ptr->b;
  142.             
  143.             Ptr = Ptr->next;
  144.         //• As long as Ptr ain't the same as top...
  145.         } while  (Ptr != top);
  146.         
  147.         do         //• ...make up the points and create a.
  148.         {        //• A circularly linked list of points.
  149.             Ptr->a =  (Ptr->a - nx) * MAXX /  (mx - nx);
  150.             Ptr->b =  (Ptr->b - ny) * MAXY /  (my - ny);
  151.             Ptr = Ptr->next;    //• Ptr points to next point.
  152.         //• Again, as long as Ptr ain't the same as top...
  153.         } while  (Ptr != top);
  154.     
  155.         n = 0;        //• ...n has 0 value.
  156.         MoveTo ( (int) Ptr->a, (int) Ptr->b);
  157.         
  158.         //• While that's true, and while incrementing n is not the same
  159.         //• as 400 times the number of points generated...
  160.         while  (n++ != MAXM * number)    
  161.         {        //• ...move the points around, like this.
  162.             Ptr->a =  (Ptr->a * 40 + Ptr->next->a) / 41;
  163.             Ptr->b =  (Ptr->b * 40 + Ptr->next->b) / 41;
  164.             RandomRGBColor();
  165.             LineTo ( (int)Ptr->a, (int)Ptr->b);
  166.             Ptr = Ptr->next;
  167.             if  (Button ())    //• Halt program when Button is pressed.
  168.             {
  169.                 done = 1;    //• It's one DONE puppy!
  170.                 break;        //• Unconditionally get the hell out.
  171.             }
  172.         }
  173.         Ptr = top;    //• Clean up the circular linked list.
  174.         do 
  175.         {
  176.             Ptr =  (Ptr2 = Ptr)->next;
  177. //            free (Ptr2);
  178.             DisposPtr (Ptr2);
  179.         } while  (Ptr != top);    //• As long as Ptr aint the top.
  180.         
  181.         
  182.         EraseRect (&linesRect);
  183.     }
  184. }
  185.  
  186.